package org.come.good;

import org.come.Frame.NPCJfram;
import org.come.Frame.PetEquipmentJframe;
import org.come.Frame.ZhuFrame;
import org.come.bean.ColorScheme;
import org.come.entity.Goodstable;
import org.come.entity.RoleSummoning;
import org.come.mouslisten.GoodsMouslisten;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.UserMessUntil;

public class PetEquip {
	/** 召唤兽使用饰品 */
	public static void PetCJS(Goodstable goodstable) {
		RoleSummoning pet = UserMessUntil.getChosePetMes();
		String[] v = goodstable.getValue().split("\\|");
		String petid = null;
		for (int i = 0; i < v.length; i++) {
			String[] vs = v[i].split("=");
			if ("召唤兽".equals(vs[0])) {
				petid = vs[1];
			}
		}
		if (petid != null) {
			if (!pet.getSummoningid().equals(petid)) {
				if (!WCSS(Integer.parseInt(pet.getSummoningid()), pet.getSummoningskin(), Integer.parseInt(petid))) {
					String tsm = "召唤兽无法佩戴该召唤兽装备";
					ZhuFrame.getZhuJpanel().addPrompt2(tsm);
					return;
				}
			}
		}
		PetEquipmentJframe.getPetEquipmentJframe().getEquipmentJpanel().Equip(pet, goodstable, -1);
	}

	/** 判断是否是5常转生召唤兽 */
	public static boolean WCSS(int petid, String skin, Integer id) {
		if (id == 200055 && ("400050".equals(skin) || "400066".equals(skin) || "400024".equals(skin) || "400073".equals(skin) || "400081".equals(skin))) {
			return true;
		}
		if ((petid >= 200102 && petid <= 200107) || (petid >= 200092 && petid <= 200096) || petid == 200076 || petid == 200068
				|| petid == 200060 || petid == 200075 || petid == 200065 || petid == 200043) {
			if (id == 200095 && "400105".equals(skin)) {
				return true;
			} else if (id == 200093 && "400103".equals(skin)) {
				return true;
			} else if (id == 200092 && "400102".equals(skin)) {
				return true;
			} else if (id == 200065 && "400079".equals(skin)) {
				return true;
			} else if (id == 200076 && "400078".equals(skin)) {
				return true;
			}
		}
		if ((getIDSKIN(id) + "").equals(skin)) {
			return true;
		}
		return false;

	}

	/** 人物转换召唤兽饰品 */
	public static void RoleCJS(Goodstable goodstable) {
		// 召唤兽|皮肤|颜色
		// goodstable.setValue("召唤兽=200124|皮肤=400528|颜色=无|根骨=200|灵性=200|力量=200|敏捷=200|品质=3924");
		// GoodsMouslisten.gooduse(goodstable,2);
		if ("彩晶石".equals(goodstable.getGoodsname())) {
			String[] vs = goodstable.getValue().split("\\|");
			int pz = 0;
			for (int i = 0; i < vs.length; i++) {
				String[] vss = vs[i].split("=");
				if ("品质".equals(vss[0])) {
					pz = Integer.parseInt(vss[1]);
				}
			}
			if (pz < 250) {
				ZhuFrame.getZhuJpanel().addPrompt2("品质超过250时可以转为指定召唤兽饰品");
			} else {
				NPCJfram.getNpcJfram().getNpcjpanel().showCJS(goodstable);
			}
		} else {
			int pz = 0;
			String color = null;
			String[] vs = goodstable.getValue().split("\\|");
			for (int i = 0; i < vs.length; i++) {
				String[] vss = vs[i].split("=");
				if ("品质".equals(vss[0])) {
					pz = Integer.parseInt(vss[1]);
				} else if ("颜色".equals(vss[0])) {
					color = vs[i];
				}
			}
			if (pz >= 1200) {
				if ("颜色=无".equals(color)) {
					ColorScheme colorScheme = UserMessUntil.getColors(0);
					if (colorScheme != null) {
						goodstable.setValue(goodstable.getValue().replace(color, "颜色=" + colorScheme.getName()));
						GoodsMouslisten.gooduse(goodstable, 2);
						return;
					}
				}
			}
		}
	}

	/** 转为指定召唤兽的物品 */
	public static void getChangeCJS(Goodstable goodstable, String pet) {
		if (!"彩晶石".equals(goodstable.getGoodsname())) {
			return;
		}
		String[] vs = goodstable.getValue().split("\\|");
		int pz = 0;
		for (int i = 0; i < vs.length; i++) {
			String[] vss = vs[i].split("=");
			if ("品质".equals(vss[0])) {
				pz = Integer.parseInt(vss[1]);
			}
		}
		if (pz < 250) {
			return;
		}
		int petid = getPetId(pet.substring(0, pet.length() - 2));
		StringBuffer buffer = new StringBuffer();
		buffer.append("召唤兽=");
		buffer.append(petid);
		buffer.append("|皮肤=");
		buffer.append(getCJSID(petid));
		buffer.append("|颜色=无|");
		buffer.append(goodstable.getValue());
		goodstable.setValue(buffer.toString());
		goodstable.setGoodsname(pet);
		goodstable.setSkin("pets" + petid);
		GoodsMouslisten.gooduse(goodstable, 2);
		GoodsListFromServerUntil.PageNumberChange(GoodsListFromServerUntil.Pagenumber);
	}

	public static int getCJSID(int id) {
		switch (id) {
			case 200095:
				return 400527;//罗刹鬼姬
			case 200124:
				return 400528;//龙马
			case 200126:
				return 400529;//冥雷
			case 200127:
				return 400530;//西域响马
			case 200156:
				return 400531;//金不换
			case 200134:
				return 400532;//松鼠
			case 200154:
				return 400533;//拨浪鼓
			case 200092:
				return 400526;//哥俩好
			case 200141:
				return 400548;//孔雀明王
			case 200132:
				return 400547;//赭炎
			case 200138:
				return 400546;//画皮娘子
			case 200135:
				return 400545;//冥灵妃子
			case 200093:
				return 400544;//剑精灵
			case 200085:
				return 400543;//黄金兽
			case 200087:
				return 400542;//泥石怪
			case 200090:
				return 400541;//冰雪魔
			case 200065:
				return 400540;//蝴蝶仙子
			case 200076:
				return 400539;//凤凰
			case 200061:
				return 400538;//冲冲虫
			case 200009:
				return 400537;//猪怪
			case 200055:
				return 400536;//符咒女娲
			case 200182:
				return 400535;//粽小仙
			case 200147:
				return 400534;//精卫
			case 200077:
				return 400549;//猴精
			case 200149:
				return 400550;//天龙女
			case 200148:
				return 400551;//吉祥果
			case 200155:
				return 400552;//狮虎兽
			case 200158:
				return 400553;//妙音鸾女
			case 200183:
				return 400559;//龙兔
			case 200184:
				return 400576;//礼·灵听
			case 200185:
				return 400557;//御·飞轩
			case 200099:
				return 500013;//浪淘沙
			case 333017:
				return 400319;//孙小圣
			case 512:
				return 500105;//白龙地
		}
		return -1;
	}

	public static int getIDSKIN(int id) {
		switch (id) {
			case 200095:
				return 400105;//罗刹鬼姬
			case 200124:
				return 400135;//龙马
			case 200126:
				return 400142;//冥雷
			case 200127:
				return 400145;//西域响马
			case 200156:
				return 400147;//金不换
			case 200134:
				return 400151;//松鼠
			case 200154:
				return 400311;//拨浪鼓
			case 200092:
				return 400102;//哥俩好
			case 200141:
				return 400181;//孔雀明王
			case 200132:
				return 400148;//赭炎
			case 200138:
				return 400140;//画皮娘子
			case 200135:
				return 400138;//冥灵妃子
			case 200093:
				return 400103;//剑精灵
			case 200085:
				return 400095;//黄金兽
			case 200087:
				return 400092;//泥石怪
			case 200090:
				return 400091;//冰雪魔
			case 200065:
				return 400079;//蝴蝶仙子
			case 200076:
				return 400078;//凤凰
			case 200061:
				return 400077;//冲冲虫
			case 200009:
				return 400051;//猪怪
			case 200055:
				return 400024;//符咒女娲
			case 200182:
				return 400509;//粽小仙
			case 200147:
				return 400316;//精卫
			case 200077:
				return 400088;//猴精
			case 200149:
				return 400134;//天龙女
			case 200148:
				return 400150;//吉祥果
			case 200155:
				return 400304;//狮虎兽
			case 200158:
				return 400506;//妙音鸾女
			case 200183:
				return 400558;//龙兔
			case 200184:
				return 400575;//礼·灵听
			case 200185:
				return 400556;//御·飞轩
			case 200099:
				return 500012;//浪淘沙
			case 333017:
				return 400318;//孙小圣
			case 512:
				return 500104;
		}
		return -1;
	}

	public static int getPetId(String pet) {
		switch (pet) {
			case "罗刹鬼姬":
				return 200095;
			case "龙马":
				return 200124;
			case "冥雷":
				return 200126;
			case "西域响马":
				return 200127;
			case "金不换":
				return 200156;
			case "松鼠":
				return 200134;
			case "拨浪鼓":
				return 200154;
			case "哥俩好":
				return 200092;
			case "孔雀明王":
				return 200141;
			case "赭炎":
				return 200132;
			case "画皮娘子":
				return 200138;
			case "冥灵妃子":
				return 200135;
			case "黄金兽":
				return 200085;
			case "剑精灵":
				return 200093;
			case "泥石怪":
				return 200087;
			case "冰雪魔":
				return 200090;
			case "蝴蝶仙子":
				return 200065;
			case "凤凰":
				return 200076;
			case "冲冲虫":
				return 200061;
			case "猪怪":
				return 200009;
			case "符咒女娲":
				return 200055;
			case "棕小仙":
				return 200182;
			case "精卫":
				return 200147;
			case "猴精":
				return 200077;
			case "天龙女":
				return 200149;
			case "吉祥果":
				return 200148;
			case "狮虎兽":
				return 200155;
			case "妙音鸾女":
				return 200158;
			case "龙兔":
				return 200183;
			case "礼·灵听":
				return 200184;
			case "御·飞轩":
				return 200185;
			case "浪淘沙":
				return 200099;
			case "孙小圣":
				return 333017;
			case "白龙帝":
				return 512;
		}
		return -1;
	}
}
